<?
include "funct.php";

if (isset($_POST["nume"], $_POST["parola1"], $_POST["parola2"], $_POST["mail"], $_POST["agree"], $_POST["day"], $_POST["month"], $_POST["year"])) {
	clean($_POST["nume"]);
	clean($_POST["parola1"]);
	clean($_POST["parola2"]);
	clean($_POST["mail"]);
	clean($_POST["agree"]);
	clean($_POST["day"]);
	clean($_POST["month"]);
	clean($_POST["year"]);
	if ($_POST["parola1"] != $_POST["parola2"])
		message_r($lang["password_i"]);
	elseif (strlen($_POST["parola1"]) < 5)
		message_r($lang["password_s"]);
	elseif (strlen($_POST["nume"]) < 5)
		message_r($lang["name_s"]);
	$rezultat = mysql_query("select * from users where name='" . $_POST["nume"] . "'");
	if (mysql_num_rows($rezultat) > 0)
		message_r($lang["name_l"]);
	$rezultat = mysql_query("select * from users where email='" . $_POST["mail"] . "'");
	if (mysql_num_rows($rezultat) > 0)
		message_r($lang["email_l"]);
	if (!is_numeric($_POST["day"]) && !is_numeric($_POST["month"]) && !is_numeric($_POST["year"]))
		message_r($lang["i_t_birday"]);
	else {
		$birday = $_POST["year"] . "-" . $_POST["month"] . "-" . $_POST["day"];
		$time = strtotime(ceas()) - strtotime($birday);
		if ($time > (60 * 60 * 24 * 365 * 12))
			$ok = 1;
		else
			$ok = 0;
		$birday = strftime("%Y-%m-%d %H:%M:%S", $time);
		if ($ok == 0)
			message_r($lang["too_young"]);
	}
	if ($_POST["agree"] == 1 && $ok == 1) {
		$rezultat = mysql_query("select * from " . $db["users"] . "");
		if (mysql_num_rows($rezultat) == 0)
			$function = "admin";
		else
			$function = "player";
		mysql_query("insert into " . $db["users"] . " set name='" . $_POST["nume"] . "', password='" . md5($_POST["parola1"]) . "', email='" . $_POST["mail"] . "', ip='" . $_SERVER['REMOTE_ADDR'] . "', birday='" . $birday . "', function='" . $function . "'");
		message_i($lang["regis_c"]);
	}
	else
		back();
}
else
	message_r($lang["empty_box"]);
header("Location: index.php");
?>
